package walletadminlogic

import (
	"context"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/model/pg/wallet"
	"navi-mumbai/app/rpc/wallet/internal/svc"
	"navi-mumbai/app/rpc/wallet/pb"
	"navi-mumbai/common/key/dbkey"
	"navi-mumbai/common/utils"
	"navi-mumbai/common/xerr"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddWalletMoneyConfigLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddWalletMoneyConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddWalletMoneyConfigLogic {
	return &AddWalletMoneyConfigLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 新增钱包币种配置
func (l *AddWalletMoneyConfigLogic) AddWalletMoneyConfig(in *pb.AddWalletMoneyConfigReq) (*pb.AddWalletMoneyConfigResp, error) {
	defer utils.RecoverPanic()

	wmc := wallet.WalletMoneyConfig{
		MoneyType:         in.MoneyType,
		MinWithdrawAmount: in.MinWithdrawAmount,
		MaxWithdrawAmount: in.MaxWithdrawAmount,
		MinDepositAmount:  in.MinDepositAmount,
		MaxDepositAmount:  in.MaxDepositAmount,
		State:             dbkey.Enable,
		MoneyIcon:         in.MoneyIcon,
		MoneyName:         in.MoneyName,
	}

	_, err := l.svcCtx.WalletMoneyConfigModel.Insert(l.ctx, &wmc)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}

	return &pb.AddWalletMoneyConfigResp{}, nil
}
